package com.hub.controller;


import com.hub.dto.PageParam;
import com.hub.dto.auth.CreateUserParam;
import com.hub.dto.auth.UserRoleParam;
import com.hub.entity.AuthUserInfo;
import com.hub.service.IAuthUserInfoService;
import com.hub.utils.ApiResultObject;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 *  用户管理Controller
 * </p>
 *
 * @author hub
 * @since 2020-05-13
 */
@RestController
@RequestMapping("/authUser")
public class AuthUserInfoController {

    @Autowired
    private IAuthUserInfoService authUserInfoService;

    @RequiresPermissions("User")
    @ApiOperation("获取用户列表")
    @PostMapping("/list")
    public ApiResultObject getList(@RequestBody PageParam<AuthUserInfo> pageParam){
        return authUserInfoService.getList(pageParam);
    }

    @RequiresPermissions("User")
    @ApiOperation("获取用户详情")
    @GetMapping("/{id}")
    public ApiResultObject getDetail(@PathVariable @NotNull Long id){
        return authUserInfoService.getUserDetail(id);
    }

    @RequiresPermissions("User")
    @ApiOperation("获取用户角色")
    @PostMapping("/getUserRole")
    public ApiResultObject getUserRole(@RequestBody @Valid UserRoleParam param){
        return authUserInfoService.getUserRole(param);
    }

    @RequiresPermissions("User")
    @ApiOperation("更新用户信息")
    @PutMapping("/{id}")
    public ApiResultObject update(@PathVariable @NotNull Long id, @RequestBody CreateUserParam param){
        return authUserInfoService.updateUser(id, param);
    }

    @RequiresPermissions("User")
    @ApiOperation("更新用户角色信息")
    @PostMapping("/updateUserRole")
    public ApiResultObject updateUserRole(@RequestBody UserRoleParam param){
        return authUserInfoService.updateUserRole(param);
    }

    @RequiresPermissions("User")
    @ApiOperation("新增用户")
    @PostMapping("/create")
    public ApiResultObject create(@RequestBody CreateUserParam param){
        return authUserInfoService.createUser(param);
    }

    @RequiresPermissions("User")
    @ApiOperation("删除用户")
    @DeleteMapping("/{id}")
    public ApiResultObject delete(@PathVariable @NotNull Long id){
        return authUserInfoService.delete(id);
    }
}

